﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.NativeMcppMethods
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using \u003CCppImplementationDetails\u003E;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Security.Principal;

namespace Microsoft.InfoCards
{
  internal class NativeMcppMethods
  {
    private NativeMcppMethods()
    {
    }

    public static unsafe byte[] X931KeyGenWrapper(
      byte[] Xp1ByteArray,
      byte[] Xp2ByteArray,
      byte[] Xq1ByteArray,
      byte[] Xq2ByteArray,
      byte[] XpByteArray,
      byte[] XqByteArray,
      int publicExponent,
      ref KeyGenRestartCodes restartCode)
    {
      byte* numPtr = (byte*) 0L;
      uint num1 = 0;
      byte[] destination = (byte[]) null;
      X931_restart_t x931RestartT = (X931_restart_t) 0;
      int length1 = Xp1ByteArray.Length;
      int length2 = XpByteArray.Length;
      \u003CModule\u003E.AssertInternal(true, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1EI\u0040FAPBOFLF\u0040\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AAq\u003F\u0024AA1\u003F\u0024AA2\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AAg\u003F\u0024AAt\u003F\u0024AAh\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AA1\u003F\u0024AAB\u003F\u0024AAy\u003F\u0024AAt\u003F\u0024AAe\u003F\u0024AAA\u003F\u0024AAr\u003F\u0024AAr\u003F\u0024AAa\u003F\u0024AAy\u003F\u0024AA\u003F9\u003F\u0024AA\u003F\u0024DO\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 130, false);
      \u003CModule\u003E.AssertInternal(length1 == Xp2ByteArray.Length, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1EI\u0040BNBJOFNC\u0040\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AAq\u003F\u0024AA1\u003F\u0024AA2\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AAg\u003F\u0024AAt\u003F\u0024AAh\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AA2\u003F\u0024AAB\u003F\u0024AAy\u003F\u0024AAt\u003F\u0024AAe\u003F\u0024AAA\u003F\u0024AAr\u003F\u0024AAr\u003F\u0024AAa\u003F\u0024AAy\u003F\u0024AA\u003F9\u003F\u0024AA\u003F\u0024DO\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 131, false);
      \u003CModule\u003E.AssertInternal(length1 == Xq1ByteArray.Length, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1EI\u0040PPLFHHPC\u0040\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AAq\u003F\u0024AA1\u003F\u0024AA2\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AAg\u003F\u0024AAt\u003F\u0024AAh\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAX\u003F\u0024AAq\u003F\u0024AA1\u003F\u0024AAB\u003F\u0024AAy\u003F\u0024AAt\u003F\u0024AAe\u003F\u0024AAA\u003F\u0024AAr\u003F\u0024AAr\u003F\u0024AAa\u003F\u0024AAy\u003F\u0024AA\u003F9\u003F\u0024AA\u003F\u0024DO\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 132, false);
      \u003CModule\u003E.AssertInternal(length1 == Xq2ByteArray.Length, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1EI\u0040LCFNHHJF\u0040\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AAq\u003F\u0024AA1\u003F\u0024AA2\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AAg\u003F\u0024AAt\u003F\u0024AAh\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAX\u003F\u0024AAq\u003F\u0024AA2\u003F\u0024AAB\u003F\u0024AAy\u003F\u0024AAt\u003F\u0024AAe\u003F\u0024AAA\u003F\u0024AAr\u003F\u0024AAr\u003F\u0024AAa\u003F\u0024AAy\u003F\u0024AA\u003F9\u003F\u0024AA\u003F\u0024DO\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 133, false);
      \u003CModule\u003E.AssertInternal(length2 == XpByteArray.Length, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1EC\u0040PNPIPOFH\u0040\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AAq\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AAg\u003F\u0024AAt\u003F\u0024AAh\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AAB\u003F\u0024AAy\u003F\u0024AAt\u003F\u0024AAe\u003F\u0024AAA\u003F\u0024AAr\u003F\u0024AAr\u003F\u0024AAa\u003F\u0024AAy\u003F\u0024AA\u003F9\u003F\u0024AA\u003F\u0024DO\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AAg\u003F\u0024AAt\u003F\u0024AAh\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 134, false);
      \u003CModule\u003E.AssertInternal(length2 == XqByteArray.Length, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1EC\u0040HAHAADLF\u0040\u003F\u0024AAX\u003F\u0024AAp\u003F\u0024AAq\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AAg\u003F\u0024AAt\u003F\u0024AAh\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAX\u003F\u0024AAq\u003F\u0024AAB\u003F\u0024AAy\u003F\u0024AAt\u003F\u0024AAe\u003F\u0024AAA\u003F\u0024AAr\u003F\u0024AAr\u003F\u0024AAa\u003F\u0024AAy\u003F\u0024AA\u003F9\u003F\u0024AA\u003F\u0024DO\u003F\u0024AAL\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AAg\u003F\u0024AAt\u003F\u0024AAh\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 135, false);
      IntPtr num2 = IntPtr.Zero;
      IntPtr num3 = IntPtr.Zero;
      IntPtr num4 = IntPtr.Zero;
      IntPtr num5 = IntPtr.Zero;
      IntPtr num6 = IntPtr.Zero;
      IntPtr num7 = IntPtr.Zero;
      RuntimeHelpers.PrepareConstrainedRegions();
      try
      {
        num2 = Marshal.AllocHGlobal(length1);
        num3 = Marshal.AllocHGlobal(length1);
        num4 = Marshal.AllocHGlobal(length1);
        num5 = Marshal.AllocHGlobal(length1);
        num6 = Marshal.AllocHGlobal(length2);
        num7 = Marshal.AllocHGlobal(length2);
        Marshal.Copy(Xp1ByteArray, 0, num2, length1);
        Marshal.Copy(Xp2ByteArray, 0, num3, length1);
        Marshal.Copy(Xq1ByteArray, 0, num4, length1);
        Marshal.Copy(Xq2ByteArray, 0, num5, length1);
        Marshal.Copy(XpByteArray, 0, num6, length2);
        Marshal.Copy(XqByteArray, 0, num7, length2);
        int error = \u003CModule\u003E.InfoCardKeyGenX931((uint) length1, (byte*) num2.ToPointer(), (byte*) num3.ToPointer(), (byte*) num4.ToPointer(), (byte*) num5.ToPointer(), (uint) length2, (byte*) num6.ToPointer(), (byte*) num7.ToPointer(), (uint) publicExponent, &numPtr, &num1, &x931RestartT);
        restartCode = (KeyGenRestartCodes) x931RestartT;
        if (0 == error)
        {
          try
          {
            if (KeyGenRestartCodes.X931RestartNone == restartCode)
            {
              \u003CModule\u003E.AssertInternal(0U != num1, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1CE\u0040MDDMNBFC\u0040\u003F\u0024AA0\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024CB\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAc\u003F\u0024AAb\u003F\u0024AAC\u003F\u0024AAr\u003F\u0024AAy\u003F\u0024AAp\u003F\u0024AAt\u003F\u0024AAo\u003F\u0024AAB\u003F\u0024AAl\u003F\u0024AAo\u003F\u0024AAb\u003F\u0024AA\u003F\u0024AA\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 194, false);
              destination = new byte[(int) num1];
              Marshal.Copy(new IntPtr((void*) numPtr), destination, 0, (int) num1);
            }
            else
              \u003CModule\u003E.AssertInternal(0U == num1, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1CE\u0040EMPLJBMF\u0040\u003F\u0024AA0\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAc\u003F\u0024AAb\u003F\u0024AAC\u003F\u0024AAr\u003F\u0024AAy\u003F\u0024AAp\u003F\u0024AAt\u003F\u0024AAo\u003F\u0024AAB\u003F\u0024AAl\u003F\u0024AAo\u003F\u0024AAb\u003F\u0024AA\u003F\u0024AA\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 204, false);
          }
          finally
          {
            \u003CModule\u003E.InfoCardKeyGenZeroAndFree(numPtr, num1);
          }
          return destination;
        }
        \u003CModule\u003E.AssertInternal(0U == num1, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1CE\u0040EMPLJBMF\u0040\u003F\u0024AA0\u003F\u0024AA\u003F5\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F\u0024DN\u003F\u0024AA\u003F5\u003F\u0024AAc\u003F\u0024AAb\u003F\u0024AAC\u003F\u0024AAr\u003F\u0024AAy\u003F\u0024AAp\u003F\u0024AAt\u003F\u0024AAo\u003F\u0024AAB\u003F\u0024AAl\u003F\u0024AAo\u003F\u0024AAb\u003F\u0024AA\u003F\u0024AA\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 219, false);
        throw new Win32Exception(error);
      }
      finally
      {
        if (IntPtr.Zero != num2)
        {
          \u003CModule\u003E.RtlSecureZeroMemory(num2.ToPointer(), (ulong) length1);
          Marshal.FreeHGlobal(num2);
        }
        if (IntPtr.Zero != num3)
        {
          \u003CModule\u003E.RtlSecureZeroMemory(num3.ToPointer(), (ulong) length1);
          Marshal.FreeHGlobal(num3);
        }
        if (IntPtr.Zero != num4)
        {
          \u003CModule\u003E.RtlSecureZeroMemory(num4.ToPointer(), (ulong) length1);
          Marshal.FreeHGlobal(num4);
        }
        if (IntPtr.Zero != num5)
        {
          \u003CModule\u003E.RtlSecureZeroMemory(num5.ToPointer(), (ulong) length1);
          Marshal.FreeHGlobal(num5);
        }
        if (IntPtr.Zero != num6)
        {
          \u003CModule\u003E.RtlSecureZeroMemory(num6.ToPointer(), (ulong) length2);
          Marshal.FreeHGlobal(num6);
        }
        if (IntPtr.Zero != num7)
        {
          \u003CModule\u003E.RtlSecureZeroMemory(num7.ToPointer(), (ulong) length2);
          Marshal.FreeHGlobal(num7);
        }
      }
    }

    public static unsafe uint InfoCardStartRpcServerWrapper(
      string uiAgentFullPath,
      IntPtr rpcCallbacks)
    {
      IntPtr hglobal = IntPtr.Zero;
      try
      {
        hglobal = Marshal.StringToHGlobalUni(uiAgentFullPath);
        return \u003CModule\u003E.InfoCardStartRpcServer((ushort*) hglobal.ToPointer(), (_RPCCALLBACKS*) rpcCallbacks.ToPointer());
      }
      finally
      {
        if (IntPtr.Zero != hglobal)
        {
          Marshal.FreeHGlobal(hglobal);
          IntPtr zero = IntPtr.Zero;
        }
      }
    }

    public static uint InfoCardStopRpcServerWrapper()
    {
      return \u003CModule\u003E.InfoCardStopRpcServer();
    }

    public static uint AdjustPrivilegesWrapper([MarshalAs(UnmanagedType.U1)] bool isTabletPC)
    {
      return \u003CModule\u003E.AdjustPrivileges(isTabletPC);
    }

    public static unsafe uint CreateAndWaitForFileOpenDialogWrapper(
      string arguments,
      WindowsIdentity callerIdentity,
      uint userProcessPid,
      ref string fileName)
    {
      uint num = 0;
      IntPtr hglobal1 = IntPtr.Zero;
      IntPtr hglobal2 = IntPtr.Zero;
      try
      {
        hglobal1 = Marshal.StringToHGlobalUni(arguments);
        hglobal2 = Marshal.StringToHGlobalUni(callerIdentity.Name);
        \u0024ArrayType\u0024\u0024\u0024BY0BAE\u0040G arrayTypeBy0BaeG;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(short&) ref arrayTypeBy0BaeG = (short) 0;
        // ISSUE: cast to a reference type
        // ISSUE: initblk instruction
        __memset((\u0024ArrayType\u0024\u0024\u0024BY0BAE\u0040G&) ((IntPtr) &arrayTypeBy0BaeG + 2), 0, 518);
        IntPtr token = callerIdentity.Token;
        num = \u003CModule\u003E.CreateAndWaitForFileOpenDialog((ushort*) hglobal1.ToPointer(), token.ToPointer(), userProcessPid, (ushort*) hglobal2.ToPointer(), (ushort*) &arrayTypeBy0BaeG);
        fileName = 0U != num ? "" : new string((char*) &arrayTypeBy0BaeG);
      }
      finally
      {
        if (IntPtr.Zero != hglobal2)
        {
          Marshal.FreeHGlobal(hglobal2);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal1)
        {
          Marshal.FreeHGlobal(hglobal1);
          IntPtr zero = IntPtr.Zero;
        }
      }
      return num;
    }

    [return: MarshalAs(UnmanagedType.U1)]
    public static unsafe bool DnsNameCompareWrapper(string dnsName1, string dnsName2)
    {
      IntPtr hglobal1 = IntPtr.Zero;
      IntPtr hglobal2 = IntPtr.Zero;
      int num = 0;
      try
      {
        hglobal1 = Marshal.StringToHGlobalUni(dnsName1);
        hglobal2 = Marshal.StringToHGlobalUni(dnsName2);
        num = \u003CModule\u003E.DnsNameCompare_W((ushort*) hglobal1.ToPointer(), (ushort*) hglobal2.ToPointer());
      }
      finally
      {
        if (IntPtr.Zero != hglobal1)
        {
          Marshal.FreeHGlobal(hglobal1);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal2)
        {
          Marshal.FreeHGlobal(hglobal2);
          IntPtr zero = IntPtr.Zero;
        }
      }
      return 0 != num;
    }

    public static unsafe uint CreateProcessAsUserHelperWrapper(
      string application,
      string commandLine,
      uint userProcessPid,
      string desktop,
      string userName,
      ref int pid)
    {
      uint num1 = 0;
      IntPtr hglobal1 = IntPtr.Zero;
      IntPtr hglobal2 = IntPtr.Zero;
      IntPtr hglobal3 = IntPtr.Zero;
      IntPtr hglobal4 = IntPtr.Zero;
      void* voidPtr = (void*) 0L;
      try
      {
        hglobal1 = Marshal.StringToHGlobalUni(application);
        hglobal2 = Marshal.StringToHGlobalUni(commandLine);
        hglobal3 = Marshal.StringToHGlobalUni(desktop);
        hglobal4 = Marshal.StringToHGlobalUni(userName);
        uint num2 = 0;
        num1 = \u003CModule\u003E.CreateProcessAsUserHelper((ushort*) hglobal1.ToPointer(), (ushort*) hglobal2.ToPointer(), userProcessPid, (ushort*) hglobal3.ToPointer(), (ushort*) hglobal4.ToPointer(), &voidPtr, &num2);
        pid = (int) num2;
      }
      finally
      {
        if (IntPtr.Zero != hglobal1)
        {
          Marshal.FreeHGlobal(hglobal1);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal2)
        {
          Marshal.FreeHGlobal(hglobal2);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal3)
        {
          Marshal.FreeHGlobal(hglobal3);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal4)
        {
          Marshal.FreeHGlobal(hglobal4);
          IntPtr zero = IntPtr.Zero;
        }
        if (0L != (IntPtr) voidPtr)
          \u003CModule\u003E.CloseHandle(voidPtr);
      }
      return num1;
    }

    public static unsafe string GetLocalDataPath(WindowsIdentity identity)
    {
      \u0024ArrayType\u0024\u0024\u0024BY0BAE\u0040G arrayTypeBy0BaeG;
      // ISSUE: initblk instruction
      __memset(ref arrayTypeBy0BaeG, 0, 520);
      int folderPathW = \u003CModule\u003E.SHGetFolderPathW((HWND__*) 0L, 28, identity.Token.ToPointer(), 0U, (ushort*) &arrayTypeBy0BaeG);
      if (folderPathW < 0)
        throw new Win32Exception(folderPathW);
      return new string((char*) &arrayTypeBy0BaeG);
    }

    public static unsafe WindowsIdentity CreateServiceExecutionIdentity(
      Process callingProcess)
    {
      WindowsIdentity identity = (WindowsIdentity) null;
      void* voidPtr = (void*) 0L;
      RuntimeHelpers.PrepareConstrainedRegions();
      try
      {
      }
      finally
      {
        if (\u003CModule\u003E.OpenProcessToken(callingProcess.Handle.ToPointer(), 14U, &voidPtr) == 0)
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        try
        {
          identity = new WindowsIdentity(new IntPtr(voidPtr));
          if (NativeMcppMethods.IsLowIntegrityIdentity(identity))
            identity = NativeMcppMethods.CreateMediumIntegrityIdentity(identity);
        }
        finally
        {
          \u003CModule\u003E.CloseHandle(voidPtr);
        }
      }
      return identity;
    }

    [return: MarshalAs(UnmanagedType.U1)]
    public static unsafe bool IsTokenValid(Process callingProcess)
    {
      void* voidPtr = (void*) 0L;
      if (\u003CModule\u003E.OpenProcessToken(callingProcess.Handle.ToPointer(), 14U, &voidPtr) == 0)
        throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
      try
      {
        _TOKEN_STATISTICS tokenStatistics;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ref tokenStatistics = 0;
        // ISSUE: cast to a reference type
        // ISSUE: initblk instruction
        __memset((_TOKEN_STATISTICS&) ((IntPtr) &tokenStatistics + 4), 0, 52);
        uint num1 = 0;
        if (\u003CModule\u003E.GetTokenInformation(voidPtr, (_TOKEN_INFORMATION_CLASS) 10, (void*) &tokenStatistics, 56U, &num1) == 0)
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        _SECURITY_LOGON_SESSION_DATA* logonSessionDataPtr = (_SECURITY_LOGON_SESSION_DATA*) 0L;
        if (0 != \u003CModule\u003E.LsaGetLogonSessionData((_LUID*) ((IntPtr) &tokenStatistics + 8), &logonSessionDataPtr))
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        uint num2 = (uint) *(int*) ((IntPtr) logonSessionDataPtr + 64L);
        \u003CModule\u003E.LsaFreeReturnBuffer((void*) logonSessionDataPtr);
        return 9U != num2;
      }
      finally
      {
        \u003CModule\u003E.CloseHandle(voidPtr);
      }
    }

    public static unsafe uint CreateProcessAsTrustedUserWrapper(
      string application,
      string commandLine,
      uint userProcessPid,
      string pDesktop,
      string pUserName,
      uint userSessionId,
      ref IntPtr trustedUserToken,
      ref IntPtr processHandle,
      ref int pid,
      IntPtr jobHandle,
      ref string trustedUserSid,
      [MarshalAs(UnmanagedType.U1)] bool fElevateToken)
    {
      uint num1 = 0;
      IntPtr hglobal1 = IntPtr.Zero;
      IntPtr hglobal2 = IntPtr.Zero;
      IntPtr hglobal3 = IntPtr.Zero;
      IntPtr hglobal4 = IntPtr.Zero;
      IntPtr hglobal5 = IntPtr.Zero;
      void* voidPtr1 = (void*) 0L;
      void* voidPtr2 = (void*) 0L;
      try
      {
        hglobal1 = Marshal.StringToHGlobalUni(application);
        hglobal2 = Marshal.StringToHGlobalUni(commandLine);
        hglobal3 = Marshal.StringToHGlobalUni(pDesktop);
        hglobal4 = Marshal.StringToHGlobalUni(pUserName);
        uint num2 = 0;
        void* voidPtr3 = (void*) 0L;
        void* hCurrentToken = (void*) 0L;
        void* voidPtr4 = (void*) 0L;
        if (IntPtr.Zero != trustedUserToken)
          hCurrentToken = trustedUserToken.ToPointer();
        if (IntPtr.Zero != jobHandle)
          voidPtr4 = jobHandle.ToPointer();
        if (!string.IsNullOrEmpty(trustedUserSid))
        {
          hglobal5 = Marshal.StringToHGlobalUni(trustedUserSid);
          if (0 == \u003CModule\u003E.ConvertStringSidToSidW((ushort*) hglobal5.ToPointer(), &voidPtr1))
            num1 = \u003CModule\u003E.GetLastError();
        }
        if (fElevateToken)
        {
          voidPtr2 = NativeMcppMethods.CreateHighIntegrityToken(hCurrentToken);
          \u003CModule\u003E.AssertInternal((IntPtr) voidPtr2 != 0L, (ushort*) &\u003CModule\u003E.\u003F\u003F_C\u0040_1BO\u0040IGNPGJKB\u0040\u003F\u0024AAh\u003F\u0024AAE\u003F\u0024AAl\u003F\u0024AAe\u003F\u0024AAv\u003F\u0024AAa\u003F\u0024AAt\u003F\u0024AAe\u003F\u0024AAd\u003F\u0024AAT\u003F\u0024AAo\u003F\u0024AAk\u003F\u0024AAe\u003F\u0024AAn\u003F\u0024AA\u003F\u0024AA\u0040, (sbyte*) &\u003CModule\u003E.\u003F\u003F_C\u0040_0CE\u0040EGKBOGOO\u0040Microsoft\u003F2InfoCards\u003F2mcppwrapper\u003F4\u0040, 722, false);
        }
        if (0U == num1)
        {
          void** voidPtr5 = (IntPtr) voidPtr2 != 0L ? &voidPtr2 : &hCurrentToken;
          num1 = \u003CModule\u003E.CreateProcessAsTrustedUser((ushort*) hglobal1.ToPointer(), (ushort*) hglobal2.ToPointer(), userProcessPid, (ushort*) hglobal3.ToPointer(), (ushort*) hglobal4.ToPointer(), userSessionId, voidPtr5, &voidPtr3, &num2, voidPtr4, &voidPtr1);
          if (0U == num1)
          {
            IntPtr num3 = new IntPtr(voidPtr3);
            processHandle = num3;
            IntPtr num4 = new IntPtr(hCurrentToken);
            trustedUserToken = num4;
            pid = (int) num2;
          }
        }
      }
      finally
      {
        if (IntPtr.Zero != hglobal1)
        {
          Marshal.FreeHGlobal(hglobal1);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal2)
        {
          Marshal.FreeHGlobal(hglobal2);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal3)
        {
          Marshal.FreeHGlobal(hglobal3);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal4)
        {
          Marshal.FreeHGlobal(hglobal4);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal5)
        {
          Marshal.FreeHGlobal(hglobal5);
          IntPtr zero = IntPtr.Zero;
        }
        if (0L != (IntPtr) voidPtr1)
        {
          ushort* numPtr = (ushort*) 0L;
          if (string.IsNullOrEmpty(trustedUserSid) && \u003CModule\u003E.ConvertSidToStringSidW(voidPtr1, &numPtr) != 0)
          {
            IntPtr ptr = new IntPtr((void*) numPtr);
            trustedUserSid = Marshal.PtrToStringUni(ptr);
          }
          \u003CModule\u003E.LocalFree(voidPtr1);
        }
        if (0L != (IntPtr) voidPtr2)
          \u003CModule\u003E.CloseHandle(voidPtr2);
      }
      return num1;
    }

    public static unsafe uint CreateJobObjectWithSD(ref IntPtr jobHandle, string trustedUserSid)
    {
      uint num1 = 0;
      IntPtr hglobal = IntPtr.Zero;
      void* voidPtr1 = (void*) 0L;
      void* voidPtr2 = (void*) 0L;
      try
      {
        if (!string.IsNullOrEmpty(trustedUserSid))
        {
          hglobal = Marshal.StringToHGlobalUni(trustedUserSid);
          if (0 == \u003CModule\u003E.ConvertStringSidToSidW((ushort*) hglobal.ToPointer(), &voidPtr1))
          {
            num1 = \u003CModule\u003E.GetLastError();
            if (0U != num1)
              goto label_11;
          }
        }
        num1 = \u003CModule\u003E.CreateJobObjectHelper(&voidPtr2, voidPtr1);
        if (0U == num1)
        {
          IntPtr num2 = new IntPtr(voidPtr2);
          jobHandle = num2;
        }
      }
      finally
      {
        if (IntPtr.Zero != hglobal)
        {
          Marshal.FreeHGlobal(hglobal);
          IntPtr zero = IntPtr.Zero;
        }
        if (0L != (IntPtr) voidPtr1)
          \u003CModule\u003E.LocalFree(voidPtr1);
      }
label_11:
      return num1;
    }

    public static unsafe IntPtr RpcCryptoOpen(string portName)
    {
      string s = (string) null;
      IntPtr hglobal1 = IntPtr.Zero;
      IntPtr hglobal2 = IntPtr.Zero;
      void* voidPtr = (void*) 0L;
      ushort* numPtr = (ushort*) 0L;
      try
      {
        hglobal1 = Marshal.StringToHGlobalUni(portName);
        int error1 = \u003CModule\u003E.RpcStringBindingComposeW((ushort*) 0L, \u003CModule\u003E.g_lrpcProtocolSequence, (ushort*) 0L, (ushort*) hglobal1.ToPointer(), (ushort*) 0L, &numPtr);
        if (0 != error1)
          throw new Win32Exception(error1);
        int error2 = \u003CModule\u003E.RpcBindingFromStringBindingW(numPtr, &voidPtr);
        if (0 != error2)
          throw new Win32Exception(error2);
        hglobal2 = Marshal.StringToHGlobalUni(s);
        int error3 = \u003CModule\u003E.RpcBindingSetAuthInfoW(voidPtr, (ushort*) 0L, 6U, 10U, (void*) 0L, 0U);
        if (0 != error3)
          throw new Win32Exception(error3);
        return new IntPtr(voidPtr);
      }
      catch (SEHException ex)
      {
        throw new Win32Exception(-2147467259);
      }
      finally
      {
        if (0L != (IntPtr) numPtr)
          \u003CModule\u003E.RpcStringFreeW(&numPtr);
        if (IntPtr.Zero != hglobal1)
        {
          Marshal.FreeHGlobal(hglobal1);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal2)
          Marshal.FreeHGlobal(hglobal2);
      }
    }

    public static unsafe void RpcCryptoClose(IntPtr hIdl, string contextKey)
    {
      IntPtr hglobal = IntPtr.Zero;
      try
      {
        hglobal = Marshal.StringToHGlobalUni(contextKey);
        \u003CModule\u003E.RpcCryptoCloseContext(hIdl.ToPointer(), (ushort*) hglobal.ToPointer());
        \u003CModule\u003E.RpcBindingFree(&hIdl.ToPointer());
      }
      catch (SEHException ex)
      {
        throw new Win32Exception(-2147467259);
      }
      finally
      {
        if (IntPtr.Zero != hglobal)
        {
          Marshal.FreeHGlobal(hglobal);
          IntPtr zero = IntPtr.Zero;
        }
      }
    }

    public static unsafe byte[] RpcCryptoDispatchRequest(
      IntPtr hIdl,
      string contextKey,
      string requestName,
      byte[] buffer,
      int index,
      int length)
    {
      IntPtr hglobal1 = IntPtr.Zero;
      IntPtr hglobal2 = IntPtr.Zero;
      IntPtr hglobal3 = IntPtr.Zero;
      _RPC_REQUEST rpcRequest;
      // ISSUE: initblk instruction
      __memset(ref rpcRequest, 0, 24);
      _RPC_RESPONSE* rpcResponsePtr1 = (_RPC_RESPONSE*) 0L;
      try
      {
        hglobal2 = Marshal.StringToHGlobalUni(contextKey);
        hglobal1 = Marshal.StringToHGlobalUni(requestName);
        IntPtr destination1 = Marshal.AllocHGlobal(length);
        hglobal3 = destination1;
        Marshal.Copy(buffer, 0, destination1, length);
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(long&) ((IntPtr) &rpcRequest + 16) = (long) hglobal3.ToPointer();
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ((IntPtr) &rpcRequest + 8) = length;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(long&) ref rpcRequest = (long) hglobal1.ToPointer();
        int error = \u003CModule\u003E.RpcCryptoDispatchRequest(hIdl.ToPointer(), (ushort*) hglobal2.ToPointer(), &rpcRequest, &rpcResponsePtr1);
        if (error < 0)
          throw new Win32Exception(error);
        if (0L == (IntPtr) rpcResponsePtr1)
          throw new Win32Exception(87);
        int length1 = *(int*) rpcResponsePtr1;
        byte[] destination2 = new byte[length1];
        _RPC_RESPONSE* rpcResponsePtr2 = (_RPC_RESPONSE*) ((IntPtr) rpcResponsePtr1 + 8L);
        if (*(long*) rpcResponsePtr2 != 0L)
          Marshal.Copy(new IntPtr((void*) *(long*) rpcResponsePtr2), destination2, 0, *(int*) rpcResponsePtr1);
        else if (length1 > 0)
          throw new Win32Exception(87);
        return destination2;
      }
      catch (SEHException ex)
      {
        throw new Win32Exception(-2147467259);
      }
      finally
      {
        if (IntPtr.Zero != hglobal2)
        {
          Marshal.FreeHGlobal(hglobal2);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal1)
        {
          Marshal.FreeHGlobal(hglobal1);
          IntPtr zero = IntPtr.Zero;
        }
        if (IntPtr.Zero != hglobal3)
        {
          Marshal.FreeHGlobal(hglobal3);
          IntPtr zero = IntPtr.Zero;
        }
        if (0L != (IntPtr) rpcResponsePtr1)
        {
          _RPC_RESPONSE* rpcResponsePtr2 = (_RPC_RESPONSE*) ((IntPtr) rpcResponsePtr1 + 8L);
          if (*(long*) rpcResponsePtr2 != 0L)
            \u003CModule\u003E.MIDL_user_free((void*) *(long*) rpcResponsePtr2);
          \u003CModule\u003E.MIDL_user_free((void*) rpcResponsePtr1);
        }
      }
    }

    public static unsafe int CryptAlgIdFromOid(string strOid)
    {
      if (string.IsNullOrEmpty(strOid))
        return 32772;
      string s = CryptoConfig.MapNameToOID(strOid);
      if (string.IsNullOrEmpty(s))
        s = strOid;
      IntPtr hglobalAnsi = Marshal.StringToHGlobalAnsi(s);
      try
      {
        _CRYPT_OID_INFO* oidInfo = \u003CModule\u003E.CryptFindOIDInfo(1U, hglobalAnsi.ToPointer(), 0U);
        if (0L == (IntPtr) oidInfo)
          throw new Win32Exception(-2147467259);
        return *(int*) ((IntPtr) oidInfo + 28L);
      }
      finally
      {
        if (IntPtr.Zero != hglobalAnsi)
          Marshal.FreeHGlobal(hglobalAnsi);
      }
    }

    [return: MarshalAs(UnmanagedType.U1)]
    public static unsafe bool GetHighAssuranceFlags(IntPtr pcertchaincontext, ref int haFlags)
    {
      ulong num1 = 0;
      haFlags = 0;
      byte num2;
      if (!(IntPtr.Zero == pcertchaincontext) && \u003CModule\u003E.SetHighAssuranceFlags((_CERT_CHAIN_CONTEXT*) pcertchaincontext.ToPointer(), &num1) != 0)
      {
        haFlags = (int) num1;
        num2 = (byte) 1;
      }
      else
        num2 = (byte) 0;
      return (bool) num2;
    }

    public static unsafe int VerifyTrust(string fileName)
    {
      IntPtr hglobal = IntPtr.Zero;
      try
      {
        hglobal = Marshal.StringToHGlobalUni(fileName);
        return (int) \u003CModule\u003E.VerifyTrust((ushort*) hglobal.ToPointer());
      }
      finally
      {
        if (IntPtr.Zero != hglobal)
        {
          Marshal.FreeHGlobal(hglobal);
          IntPtr zero = IntPtr.Zero;
        }
      }
    }

    public static unsafe void CheckSIDAgainstCurrentRpcUser(string strSid)
    {
      IntPtr hglobal = IntPtr.Zero;
      void* voidPtr = (void*) 0L;
      int num1 = 0;
      int num2 = 0;
      try
      {
        hglobal = Marshal.StringToHGlobalUni(strSid);
        if (\u003CModule\u003E.ConvertStringSidToSidW((ushort*) hglobal.ToPointer(), &voidPtr) == 0)
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        if (0 != \u003CModule\u003E.RpcImpersonateClient((void*) 0L))
          throw new SecurityException();
        num2 = 1;
        if (\u003CModule\u003E.CheckTokenMembership((void*) 0L, voidPtr, &num1) == 0)
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        if (num1 == 0)
          throw new SecurityException();
      }
      finally
      {
        if (num2 != 0 && \u003CModule\u003E.RevertToSelf() == 0)
          throw new InvalidOperationException();
        if (IntPtr.Zero != hglobal)
        {
          Marshal.FreeHGlobal(hglobal);
          IntPtr zero = IntPtr.Zero;
        }
        if (0L != (IntPtr) voidPtr)
          \u003CModule\u003E.LocalFree(voidPtr);
      }
    }

    [return: MarshalAs(UnmanagedType.U1)]
    public static unsafe bool IsOsVistaOrGreater()
    {
      _OSVERSIONINFOW osversioninfow;
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      ^(int&) ref osversioninfow = 276;
      // ISSUE: cast to a reference type
      // ISSUE: initblk instruction
      __memset((_OSVERSIONINFOW&) ((IntPtr) &osversioninfow + 4), 0, 272);
      if (\u003CModule\u003E.GetVersionExW(&osversioninfow) == 0)
        throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      return (uint) ^(int&) ((IntPtr) &osversioninfow + 4) >= 6U;
    }

    [return: MarshalAs(UnmanagedType.U1)]
    public static unsafe bool IsLowIntegrityIdentity(WindowsIdentity identity)
    {
      bool flag = false;
      _OSVERSIONINFOW osversioninfow;
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      ^(int&) ref osversioninfow = 276;
      // ISSUE: cast to a reference type
      // ISSUE: initblk instruction
      __memset((_OSVERSIONINFOW&) ((IntPtr) &osversioninfow + 4), 0, 272);
      if (\u003CModule\u003E.GetVersionExW(&osversioninfow) == 0)
        throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      if (((uint) ^(int&) ((IntPtr) &osversioninfow + 4) >= 6U ? 1 : 0) != 0)
      {
        _TOKEN_MANDATORY_LABEL* tokenMandatoryLabelPtr = (_TOKEN_MANDATORY_LABEL*) 0L;
        void* voidPtr = (void*) 0L;
        uint num1 = 0;
        uint num2 = 0;
        RuntimeHelpers.PrepareConstrainedRegions();
        try
        {
        }
        finally
        {
          try
          {
            if (\u003CModule\u003E.GetTokenInformation(identity.Token.ToPointer(), (_TOKEN_INFORMATION_CLASS) 25, (void*) 0L, 0U, &num1) == 0)
            {
              uint lastError = \u003CModule\u003E.GetLastError();
              if (122U != lastError)
                throw new Win32Exception((int) lastError);
              tokenMandatoryLabelPtr = (_TOKEN_MANDATORY_LABEL*) \u003CModule\u003E.LocalAlloc(64U, (ulong) num1);
              if ((IntPtr) tokenMandatoryLabelPtr == IntPtr.Zero)
                throw new OutOfMemoryException();
            }
            if (\u003CModule\u003E.GetTokenInformation(identity.Token.ToPointer(), (_TOKEN_INFORMATION_CLASS) 25, (void*) tokenMandatoryLabelPtr, num1, &num1) == 0)
              throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
            if (\u003CModule\u003E.CreateWellKnownSid((WELL_KNOWN_SID_TYPE) 66, (void*) 0L, (void*) 0L, &num2) == 0)
            {
              uint lastError = \u003CModule\u003E.GetLastError();
              if (122U != lastError)
                throw new Win32Exception((int) lastError);
              voidPtr = \u003CModule\u003E.LocalAlloc(64U, (ulong) num2);
              if ((IntPtr) voidPtr == IntPtr.Zero)
                throw new OutOfMemoryException();
            }
            if (\u003CModule\u003E.CreateWellKnownSid((WELL_KNOWN_SID_TYPE) 66, (void*) 0L, voidPtr, &num2) == 0)
              throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
            flag = \u003CModule\u003E.EqualSid(voidPtr, (void*) *(long*) tokenMandatoryLabelPtr) != 0 || flag;
          }
          finally
          {
            if ((IntPtr) voidPtr != IntPtr.Zero)
              \u003CModule\u003E.LocalFree(voidPtr);
            if ((IntPtr) tokenMandatoryLabelPtr != IntPtr.Zero)
              \u003CModule\u003E.LocalFree((void*) tokenMandatoryLabelPtr);
          }
        }
      }
      return flag;
    }

    public static unsafe WindowsIdentity CreateMediumIntegrityIdentity(
      WindowsIdentity identity)
    {
      WindowsIdentity windowsIdentity = (WindowsIdentity) null;
      _OSVERSIONINFOW osversioninfow;
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      ^(int&) ref osversioninfow = 276;
      // ISSUE: cast to a reference type
      // ISSUE: initblk instruction
      __memset((_OSVERSIONINFOW&) ((IntPtr) &osversioninfow + 4), 0, 272);
      if (\u003CModule\u003E.GetVersionExW(&osversioninfow) == 0)
        throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      if (((uint) ^(int&) ((IntPtr) &osversioninfow + 4) >= 6U ? 1 : 0) == 0)
        throw new InvalidOperationException();
      void* voidPtr = (void*) 0L;
      _TOKEN_MANDATORY_LABEL* tokenMandatoryLabelPtr1 = (_TOKEN_MANDATORY_LABEL*) 0L;
      uint num1 = 0;
      RuntimeHelpers.PrepareConstrainedRegions();
      try
      {
      }
      finally
      {
        try
        {
          if (\u003CModule\u003E.DuplicateTokenEx(identity.Token.ToPointer(), 142U, (_SECURITY_ATTRIBUTES*) 0L, (_SECURITY_IMPERSONATION_LEVEL) 2, (_TOKEN_TYPE) 2, &voidPtr) == 0)
            throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
          if (\u003CModule\u003E.CreateWellKnownSid((WELL_KNOWN_SID_TYPE) 67, (void*) 0L, (void*) 0L, &num1) == 0)
          {
            uint lastError = \u003CModule\u003E.GetLastError();
            if (122U != lastError)
              throw new Win32Exception((int) lastError);
          }
          uint num2 = (uint) ((ulong) num1 + 16UL);
          tokenMandatoryLabelPtr1 = (_TOKEN_MANDATORY_LABEL*) \u003CModule\u003E.LocalAlloc(64U, (ulong) num2);
          if ((IntPtr) tokenMandatoryLabelPtr1 == IntPtr.Zero)
            throw new OutOfMemoryException();
          _TOKEN_MANDATORY_LABEL* tokenMandatoryLabelPtr2 = (_TOKEN_MANDATORY_LABEL*) ((IntPtr) tokenMandatoryLabelPtr1 + 16L);
          *(long*) tokenMandatoryLabelPtr1 = (long) tokenMandatoryLabelPtr2;
          *(int*) ((IntPtr) tokenMandatoryLabelPtr1 + 8L) = 96;
          if (\u003CModule\u003E.CreateWellKnownSid((WELL_KNOWN_SID_TYPE) 67, (void*) 0L, (void*) tokenMandatoryLabelPtr2, &num1) == 0)
            throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
          if (\u003CModule\u003E.SetTokenInformation(voidPtr, (_TOKEN_INFORMATION_CLASS) 25, (void*) tokenMandatoryLabelPtr1, num2) == 0)
            throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
          windowsIdentity = new WindowsIdentity(new IntPtr(voidPtr));
        }
        finally
        {
          if ((IntPtr) voidPtr != IntPtr.Zero)
            \u003CModule\u003E.CloseHandle(voidPtr);
          if ((IntPtr) tokenMandatoryLabelPtr1 != IntPtr.Zero)
            \u003CModule\u003E.LocalFree((void*) tokenMandatoryLabelPtr1);
        }
      }
      return windowsIdentity;
    }

    public static unsafe void* CreateHighIntegrityToken(void* hCurrentToken)
    {
      _OSVERSIONINFOW osversioninfow;
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      ^(int&) ref osversioninfow = 276;
      // ISSUE: cast to a reference type
      // ISSUE: initblk instruction
      __memset((_OSVERSIONINFOW&) ((IntPtr) &osversioninfow + 4), 0, 272);
      if (\u003CModule\u003E.GetVersionExW(&osversioninfow) == 0)
        throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      if (((uint) ^(int&) ((IntPtr) &osversioninfow + 4) >= 6U ? 1 : 0) == 0)
        throw new InvalidOperationException();
      void* voidPtr = (void*) 0L;
      _TOKEN_MANDATORY_LABEL* tokenMandatoryLabelPtr1 = (_TOKEN_MANDATORY_LABEL*) 0L;
      uint num1 = 0;
      RuntimeHelpers.PrepareConstrainedRegions();
      try
      {
      }
      finally
      {
        try
        {
          if (\u003CModule\u003E.DuplicateTokenEx(hCurrentToken, 139U, (_SECURITY_ATTRIBUTES*) 0L, (_SECURITY_IMPERSONATION_LEVEL) 2, (_TOKEN_TYPE) 1, &voidPtr) == 0)
            throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
          if (\u003CModule\u003E.CreateWellKnownSid((WELL_KNOWN_SID_TYPE) 68, (void*) 0L, (void*) 0L, &num1) == 0)
          {
            uint lastError = \u003CModule\u003E.GetLastError();
            if (122U != lastError)
              throw new Win32Exception((int) lastError);
          }
          uint num2 = (uint) ((ulong) num1 + 16UL);
          tokenMandatoryLabelPtr1 = (_TOKEN_MANDATORY_LABEL*) \u003CModule\u003E.LocalAlloc(64U, (ulong) num2);
          if ((IntPtr) tokenMandatoryLabelPtr1 == IntPtr.Zero)
            throw new OutOfMemoryException();
          _TOKEN_MANDATORY_LABEL* tokenMandatoryLabelPtr2 = (_TOKEN_MANDATORY_LABEL*) ((IntPtr) tokenMandatoryLabelPtr1 + 16L);
          *(long*) tokenMandatoryLabelPtr1 = (long) tokenMandatoryLabelPtr2;
          *(int*) ((IntPtr) tokenMandatoryLabelPtr1 + 8L) = 96;
          if (\u003CModule\u003E.CreateWellKnownSid((WELL_KNOWN_SID_TYPE) 68, (void*) 0L, (void*) tokenMandatoryLabelPtr2, &num1) == 0)
            throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
          if (\u003CModule\u003E.SetTokenInformation(voidPtr, (_TOKEN_INFORMATION_CLASS) 25, (void*) tokenMandatoryLabelPtr1, num2) == 0)
            throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        }
        finally
        {
          if ((IntPtr) tokenMandatoryLabelPtr1 != IntPtr.Zero)
            \u003CModule\u003E.LocalFree((void*) tokenMandatoryLabelPtr1);
        }
      }
      return voidPtr;
    }

    public static unsafe void AdjustServiceProcessSecurity()
    {
      void* voidPtr = (void*) 0L;
      _ACL* aclPtr1 = (_ACL*) 0L;
      _ACL* aclPtr2 = (_ACL*) 0L;
      uint num1 = 68;
      _EXPLICIT_ACCESS_W explicitAccessW;
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      ^(int&) ref explicitAccessW = 0;
      // ISSUE: cast to a reference type
      // ISSUE: initblk instruction
      __memset((_EXPLICIT_ACCESS_W&) ((IntPtr) &explicitAccessW + 4), 0, 44);
      try
      {
        uint securityInfo = \u003CModule\u003E.GetSecurityInfo(\u003CModule\u003E.GetCurrentProcess(), (_SE_OBJECT_TYPE) 6, 4U, (void**) 0L, (void**) 0L, &aclPtr1, (_ACL**) 0L, &voidPtr);
        if (0U != securityInfo)
          throw new Win32Exception((int) securityInfo);
        \u0024ArrayType\u0024\u0024\u0024BY0BB\u0040K arrayTypeBy0BbK;
        if (\u003CModule\u003E.CreateWellKnownSid((WELL_KNOWN_SID_TYPE) 11, (void*) 0L, (void*) &arrayTypeBy0BbK, &num1) == 0)
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ref explicitAccessW = 1048576;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ((IntPtr) &explicitAccessW + 4) = 1;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ((IntPtr) &explicitAccessW + 28) = 0;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ((IntPtr) &explicitAccessW + 32) = 5;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(long&) ((IntPtr) &explicitAccessW + 40) = (long) &arrayTypeBy0BbK;
        uint num2 = \u003CModule\u003E.SetEntriesInAclW(1U, &explicitAccessW, aclPtr1, &aclPtr2);
        if (0U != num2)
          throw new Win32Exception((int) num2);
        uint num3 = \u003CModule\u003E.SetSecurityInfo(\u003CModule\u003E.GetCurrentProcess(), (_SE_OBJECT_TYPE) 6, 4U, (void*) 0L, (void*) 0L, aclPtr2, (_ACL*) 0L);
        if (0U != num3)
          throw new Win32Exception((int) num3);
      }
      finally
      {
        if (0L != (IntPtr) aclPtr2)
          \u003CModule\u003E.LocalFree((void*) aclPtr2);
        if (0L != (IntPtr) voidPtr)
          \u003CModule\u003E.LocalFree(voidPtr);
      }
    }

    [return: MarshalAs(UnmanagedType.U1)]
    public static unsafe bool IsCardSpaceTcserverInstance(int pid, string trustedUserSid)
    {
      bool flag = false;
      void* voidPtr1 = (void*) 0L;
      void* voidPtr2 = (void*) 0L;
      ushort* numPtr = (ushort*) 0L;
      IntPtr hglobal = IntPtr.Zero;
      try
      {
        voidPtr1 = \u003CModule\u003E.OpenProcess(1024U, 0, (uint) pid);
        if (0L != (IntPtr) voidPtr1)
        {
          if (\u003CModule\u003E.OpenProcessToken(voidPtr1, 8U, &voidPtr2) != 0)
          {
            \u0024ArrayType\u0024\u0024\u0024BY0EE\u0040E arrayTypeBy0EeE;
            // ISSUE: cast to a reference type
            // ISSUE: explicit reference operation
            ^(sbyte&) ref arrayTypeBy0EeE = (sbyte) 0;
            // ISSUE: cast to a reference type
            // ISSUE: initblk instruction
            __memset((\u0024ArrayType\u0024\u0024\u0024BY0EE\u0040E&) ((IntPtr) &arrayTypeBy0EeE + 1), 0, 67);
            uint num = 0;
            if (\u003CModule\u003E.GetTokenInformation(voidPtr2, (_TOKEN_INFORMATION_CLASS) 4, (void*) &arrayTypeBy0EeE, 68U, &num) != 0)
            {
              _TOKEN_OWNER* tokenOwnerPtr = (_TOKEN_OWNER*) &arrayTypeBy0EeE;
              // ISSUE: cast to a reference type
              // ISSUE: explicit reference operation
              if (\u003CModule\u003E.ConvertSidToStringSidW((void*) ^(long&) ref arrayTypeBy0EeE, &numPtr) != 0)
              {
                hglobal = Marshal.StringToHGlobalUni(trustedUserSid);
                flag = 0 == \u003CModule\u003E._wcsnicmp((ushort*) hglobal.ToPointer(), numPtr, 68UL);
              }
            }
          }
        }
      }
      finally
      {
        if (0L != (IntPtr) numPtr)
          \u003CModule\u003E.LocalFree((void*) numPtr);
        if (0L != (IntPtr) voidPtr2)
          \u003CModule\u003E.CloseHandle(voidPtr2);
        if (0L != (IntPtr) voidPtr1)
          \u003CModule\u003E.CloseHandle(voidPtr1);
        if (IntPtr.Zero != hglobal)
          Marshal.FreeHGlobal(hglobal);
      }
      return flag;
    }

    public static unsafe void AddSystemAccessToProcess(IntPtr RpcHandle, uint callerPid)
    {
      bool flag = false;
      void* voidPtr1 = (void*) 0L;
      _ACL* aclPtr1 = (_ACL*) 0L;
      _ACL* aclPtr2 = (_ACL*) 0L;
      void* voidPtr2 = (void*) 0L;
      _EXPLICIT_ACCESS_W explicitAccessW;
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      ^(int&) ref explicitAccessW = 0;
      // ISSUE: cast to a reference type
      // ISSUE: initblk instruction
      __memset((_EXPLICIT_ACCESS_W&) ((IntPtr) &explicitAccessW + 4), 0, 44);
      \u0024ArrayType\u0024\u0024\u0024BY0EE\u0040E arrayTypeBy0EeE;
      // ISSUE: cast to a reference type
      // ISSUE: explicit reference operation
      ^(sbyte&) ref arrayTypeBy0EeE = (sbyte) 0;
      // ISSUE: cast to a reference type
      // ISSUE: initblk instruction
      __memset((\u0024ArrayType\u0024\u0024\u0024BY0EE\u0040E&) ((IntPtr) &arrayTypeBy0EeE + 1), 0, 67);
      uint num1 = 68;
      try
      {
        uint num2 = (uint) \u003CModule\u003E.RpcImpersonateClient(RpcHandle.ToPointer());
        if (0U != num2)
          throw new Win32Exception((int) num2);
        flag = true;
        voidPtr1 = \u003CModule\u003E.OpenProcess(393216U, 0, callerPid);
        if (0L == (IntPtr) voidPtr1)
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        uint securityInfo = \u003CModule\u003E.GetSecurityInfo(voidPtr1, (_SE_OBJECT_TYPE) 6, 4U, (void**) 0L, (void**) 0L, &aclPtr1, (_ACL**) 0L, &voidPtr2);
        if (0U != securityInfo)
          throw new Win32Exception((int) securityInfo);
        if (\u003CModule\u003E.CreateWellKnownSid((WELL_KNOWN_SID_TYPE) 22, (void*) 0L, (void*) &arrayTypeBy0EeE, &num1) == 0)
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ref explicitAccessW = 2035711;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ((IntPtr) &explicitAccessW + 4) = 1;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ((IntPtr) &explicitAccessW + 28) = 0;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(int&) ((IntPtr) &explicitAccessW + 32) = 1;
        // ISSUE: cast to a reference type
        // ISSUE: explicit reference operation
        ^(long&) ((IntPtr) &explicitAccessW + 40) = (long) &arrayTypeBy0EeE;
        uint num3 = \u003CModule\u003E.SetEntriesInAclW(1U, &explicitAccessW, aclPtr1, &aclPtr2);
        if (0U != num3)
          throw new Win32Exception((int) num3);
        uint num4 = \u003CModule\u003E.SetSecurityInfo(voidPtr1, (_SE_OBJECT_TYPE) 6, 4U, (void*) 0L, (void*) 0L, aclPtr2, (_ACL*) 0L);
        if (0U != num4)
          throw new Win32Exception((int) num4);
      }
      finally
      {
        if (0L != (IntPtr) aclPtr2)
          \u003CModule\u003E.LocalFree((void*) aclPtr2);
        if (0L != (IntPtr) voidPtr2)
          \u003CModule\u003E.LocalFree(voidPtr2);
        if (0L != (IntPtr) voidPtr1)
          \u003CModule\u003E.CloseHandle(voidPtr1);
        if (flag)
          \u003CModule\u003E.RpcRevertToSelf();
      }
    }

    [return: MarshalAs(UnmanagedType.U1)]
    public static unsafe bool PathSupportsPersistedSecurity(string path)
    {
      bool flag = false;
      string pathRoot = Path.GetPathRoot(path);
      RuntimeHelpers.PrepareConstrainedRegions();
      try
      {
      }
      finally
      {
        GCHandle gcHandle = GCHandle.Alloc((object) pathRoot, GCHandleType.Pinned);
        \u0024ArrayType\u0024\u0024\u0024BY0BAF\u0040G arrayTypeBy0BafG1;
        // ISSUE: initblk instruction
        __memset(ref arrayTypeBy0BafG1, 0, 522);
        \u0024ArrayType\u0024\u0024\u0024BY0BAF\u0040G arrayTypeBy0BafG2;
        // ISSUE: initblk instruction
        __memset(ref arrayTypeBy0BafG2, 0, 522);
        uint num1 = 0;
        uint num2 = 0;
        uint num3 = 0;
        if (\u003CModule\u003E.GetVolumeInformationW((ushort*) gcHandle.AddrOfPinnedObject().ToPointer(), (ushort*) &arrayTypeBy0BafG1, 261U, &num1, &num2, &num3, (ushort*) &arrayTypeBy0BafG2, 261U) != 0)
        {
          flag = ((int) num3 & 8) != 0 || flag;
          gcHandle.Free();
        }
        else
        {
          gcHandle.Free();
          throw new Win32Exception((int) \u003CModule\u003E.GetLastError());
        }
      }
      return flag;
    }
  }
}
